package com.dmwork.service.customer.controller.front.feign;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dmwork.common.base.result.R;
import com.dmwork.service.customer.entity.Customer;
import com.dmwork.service.customer.service.CustomerFollowerService;
import com.dmwork.service.customer.service.CustomerService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;


@Slf4j
@RestController
@RequestMapping("/front/dm_work/customer/feign")
public class FrontFeignCustomerController {

    @Autowired
    private CustomerService customerService;
    @Autowired
    private CustomerFollowerService customerFollowerService;

    @ApiOperation("获取当前用户的基本信息")
    @GetMapping("get_base_info/{customerId}")
    public R getBaseInfo(@PathVariable("customerId") String customerId) {
        Customer customer = customerService.getById(customerId);
        HashMap<String, String> result = new HashMap<>();
        return R.ok().data("customerName", customer.getName()).data("avatar", customer.getAvatar());
    }

    @ApiOperation("获取多个用户的基本信息")
    @PostMapping("get_base_info_list")
    public R getBaseInfoList(@RequestBody List<String> customerIdList) {
        List<Customer> customerList = customerService.listByIds(customerIdList);
        HashMap<String, List<String>> resultMap = new HashMap<>();
        for (Customer customer : customerList) {
            ArrayList<String> arrayList = new ArrayList<>();
            arrayList.add(customer.getName()); //第一个元素是用户名，第二个元素是头像
            arrayList.add(customer.getAvatar());
            resultMap.put(customer.getId(), arrayList);
        }
        return R.ok().data("result", resultMap);
    }

    @ApiOperation("获取所有关注的用户的基本信息")
    @GetMapping("get_followed_customer_base_info_list/{followerId}")
    public R getFollowedCustomerBaseInfoList(@PathVariable("followerId") String followerId) {
        List<String> followedCustomerIdList = customerFollowerService.getFollowedCustomerIdList(followerId);
        HashMap<String, List<String>> resultMap = new LinkedHashMap<>();
        if (followedCustomerIdList.size() > 0) {
            List<Customer> customerList = customerService.listByIds(followedCustomerIdList);
            for (Customer customer : customerList) {
                ArrayList<String> arrayList = new ArrayList<>();
                arrayList.add(customer.getName()); //第一个元素是用户名，第二个元素是头像
                arrayList.add(customer.getAvatar());
                resultMap.put(customer.getId(), arrayList);
            }
        }
        return R.ok().data("result", resultMap);
    }

}
